package it.openHWHackaton.Match;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;

import twitter4j.conf.ConfigurationBuilder;

public class RAtableSoccerAccount {
    private static final String TWITTER_CONSUMER_KEY = "dj4rd1kFVNFphTRDU7Xog";
    private static final String TWITTER_SECRET_KEY = "kV9HW02g82uVfoLztVzxZ5CFvSoHlk4naiuQgWmC0E";
    private static final String TWITTER_ACCESS_TOKEN = "2322251280-i8bYOZJiv6c63BJk5srTMQHdGeiHnU42WhmAXxa";
    private static final String TWITTER_ACCESS_TOKEN_SECRET = "S0vqGJ6rAQSUX1GwBHgSZFvWHtFBIGblPD7thv8twOEfK";
    private static final String TWITTER_USERNAME="RATableSoccer";
    
   
    
    
    public RAtableSoccerAccount() {
        
    }
    
    
    public void sendTweet(String message) throws TwitterException {
         ConfigurationBuilder cb = new ConfigurationBuilder();
                    cb.setDebugEnabled(true)
                        .setOAuthConsumerKey(TWITTER_CONSUMER_KEY)
                        .setOAuthConsumerSecret(TWITTER_SECRET_KEY)
                        .setOAuthAccessToken(TWITTER_ACCESS_TOKEN)
                        .setOAuthAccessTokenSecret(TWITTER_ACCESS_TOKEN_SECRET);
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();
        Date now = new Date();
        twitter.updateStatus(message+" #ReplyHackathon ");    
        
        
    }
    
    public List<String> getTweet() throws TwitterException {
        ConfigurationBuilder cb = new ConfigurationBuilder();
                   cb.setDebugEnabled(true)
                       .setOAuthConsumerKey(TWITTER_CONSUMER_KEY)
                       .setOAuthConsumerSecret(TWITTER_SECRET_KEY)
                       .setOAuthAccessToken(TWITTER_ACCESS_TOKEN)
                       .setOAuthAccessTokenSecret(TWITTER_ACCESS_TOKEN_SECRET);
        List<String> risp = new ArrayList<String>();
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();
        Query query = new Query(TWITTER_USERNAME);
        QueryResult result;
        result = twitter.search(query);
        List<Status> tweets =result.getTweets();
        for (Status tweet : tweets) {
            risp.add(tweet.getText());
                    
        }
        return risp;
    }
   
   
  
 
}
